﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Data;

namespace GroundWater
{
    /// <summary>
    /// 
    /// </summary>
    [DataObject(true)]
    public class ProductsDataObject
    {
        /// <summary>
        /// 
        /// </summary>
        private DataSet _products;

        /// <summary>
        /// 
        /// </summary>
        public ProductsDataObject()
        {
            this._products = HttpContext.Current.Session["Products"] as DataSet;

            if (this._products == null)
            {
                this._products = new DataSet();
                this._products.ReadXmlSchema(HttpContext.Current.Server.MapPath(@"~/App_Data/products.xsd"));
                this._products.ReadXml(HttpContext.Current.Server.MapPath(@"~/App_Data/products.xml"));

                HttpContext.Current.Session["Products"] = this._products;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        private DataTable ProductTable
        {
            get { return this._products.Tables["products"]; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [DataObjectMethod(DataObjectMethodType.Select)]
        public DataView Select()
        {
            this.ProductTable.DefaultView.Sort = "ProductID";
            return this.ProductTable.DefaultView;
        }
    }
}
